{extend name="layout:base" /}
{block name="main_content"}
  <div class="page-content">
    <!--主题-->
    <?php if(!empty($current_page)): ?>
      <div class="page-header">
        <h1>
          您当前操作
          <small>
            <i class="ace-icon fa fa-angle-double-right"></i>
            {$current_page.title|default=''}
          </small>
        </h1>
      </div>
    <?php endif; ?>
    <div class="row">
      <?php if(!empty($notice)): ?>
        <div class="alert alert-block alert-success">
          <button type="button" class="close" data-dismiss="alert">
            <i class="ace-icon fa fa-times"></i>
          </button>
          <i class="ace-icon fa fa-check green"></i>
          {$notice}
        </div>
      <?php endif; ?>
      <div class="col-xs-12">
        <form class="form-horizontal adminform" id="model-form" method="post" action="">
          <div class="form-group">
            <label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 
              旧密码：
            </label>
            <div class="col-sm-10">
              <input type="password" name="old_password" placeholder="请输入您的登录密码" class="col-xs-10 col-sm-5" value="" />
            </div>
          </div>
          <div class="space-4"></div>

          <div class="form-group">
            <label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 
              新密码：
            </label>
            <div class="col-sm-10">
              <input type="password" id="password" name="password" placeholder="请输入新登录密码" class="col-xs-10 col-sm-5" value="" />
            </div>
          </div>
          <div class="space-4"></div>

          <div class="form-group">
            <label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 
              确认密码：
            </label>
            <div class="col-sm-10">
              <input type="password" name="confirm_password" placeholder="再次输入新登录密码" class="col-xs-10 col-sm-5" value="" />
            </div>
          </div>
          <div class="space-4"></div>

          <div class="clearfix form-actions">
            <div class="col-md-offset-3 col-md-9">
              <button class="btn btn-info" type="submit">
                <i class="ace-icon fa fa-check bigger-110"></i>
                保存
              </button>

              &nbsp; &nbsp; &nbsp;
              <button class="btn" type="reset">
                <i class="ace-icon fa fa-undo bigger-110"></i>
                重置
              </button>
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>
{/block}
{block name="page_js"}
  <script src="/static/plugins/jquery-validate/jquery.validate.min.js"></script>
  <script type="text/javascript">
    $("form#model-form").validate({
      rules:{
        "old_password":{
          required: true,
          remote: {
            url: "{:url('ajax_valid_password')}",
            type: "post"
          }
        },"password":{
          required: true,
          minlength: 6,
          maxlength: 20
        },"confirm_password":{
          required: true,
          equalTo: "#password"
        }
      },
      messages:{
        "old_password":{
          required: "请输入您的登录密码",
          remote: "请的登录密码不正确"
        },"password":{
          required: "请输入新登录密码",
          minlength: "登录密码长度必须在6-20之间",
          maxlength: "登录密码长度必须在6-20之间"
        },"confirm_password":{
          required: "请再次输入新登录密码",
          equalTo: "两次输入的密码不一致"
        }
      },
      errorClass: "help-inline input-error",
      errorElement: "span",
      highlight:function(element, errorClass, validClass) {
        $(element).parents('.form-group').addClass('has-error');
      },
      unhighlight: function(element, errorClass, validClass) {
        $(element).parents('.form-group').removeClass('has-error');
      },
      submitHandler: function(form){
        var $form = $(form);
        $.ajax({
          url: $form.attr("action"),
          type: $form.attr("method"),
          dataType: "JSON",
          data: $form.serialize(),
          success: function(data){
            if(data.code){
              location.href = data["url"];
            }else{
              alert(data["msg"]);
            }
          }, error: function () {
            alert("数据执行错误！");
          }
        });
      }
    });
  </script>
{/block}